<template>
	<view style="margin-top: 30%;">
		<view class="pageHead"><image :src="personal.avatarUrl" mode="widthFix"></image></view>
		<view class="title">{{personal.nickName}}</view>
		
		<view>请邀请您的另一半，一起开通体验吧~</view>
		
		<view class="bindBtn">
			<button type="default" open-type="share" v-if="isType == 1">邀请另一半</button>
			<button type="default" v-if="isType == 2" @tap="takeInvite">接收邀请</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				personal:{},
				isType:1,
				id:''
			}
		},
		onLoad(option) {
			if(option.id){
				this.isType = 2;
				this.id = option.id;
			}
			this.infoMes();
		},
		methods: {
			/**
			 * @author smallfour
			 * @description 获取个人信息
			 */
			infoMes:function(){
				this.$api.getMes({}).then(res => {
					if(res.code == 200){
						// 已有情侣
						if(res.data.loveid){
							uni.setStorage({
								key:"loveStatus",
								data:{
									loveid:res.data.loveid
								}
							})
							uni.switchTab({
								url:'/pages/tabBar/index'
							})
						}
						this.personal = res.data;
					}
				})
			},
			
			/**
			 * @author smallfour
			 * @description 接受邀请
			 */
			takeInvite:function(){
				this.$api.bindLovers({love_id:this.id}).then(res => {
					if(res.code == 200){
						this.msg('绑定成功');
						uni.setStorage({
							key:"loveStatus",
							data:{
								loveid:this.id
							}
						})
						setTimeout(function(){
							uni.switchTab({
								url:'/pages/tabBar/index'
							})
						},1000)
					}
				})
			},
			
			/**
			 * @author smallfour
			 * @description 分享邀请
			 */
			onShareAppMessage(res){
				return {
					title: '来和我恋爱吧',
					path: '/pages/tabBar/bindRelation?id=' + this.personal.id
				}
			}
		}
	}
</script>

<style lang="scss">
	.pageHead{
		text-align: center;
		padding: 160rpx 0 0;
		image{
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;
		}
	}
	.title{
		text-align: center;
		font-size: 36rpx;
		padding: 10rpx 0;
	}
	.title + view{
		text-align: center;
		padding: 80rpx 0;
	}
	.bindBtn{
		button{
			margin: 0 80rpx;
			background: linear-gradient(90deg,#ec8b8b, #d85a5b);
			border-radius: 40rpx;
			color: #FFFFFF;
		}
		
		button::after{
			border:none;
		}
	}
</style>
